// 导入express模块
const express = require('express')
// 创建router
const router = express.Router()
// 导入文章的路由处理函数模块
const article_handler = require('../router_handler/article')

// 导入验证数据的中间件
const expressJoi = require('@escook/express-joi')
// 导入文章的验证模块
const { add_article_schema, delete_article_schema, show_article_schema, searchSort_article_schema,
    update_article_schema, save_article_schema,keySearch_article_schema } = require('../schema/article')


// post 请求  添加博客
router.post('/add', expressJoi(add_article_schema), article_handler.addArticle)
// post 请求  修改博客
router.post('/updateblog', expressJoi(update_article_schema), article_handler.updateArticle)
// post 请求  删除博客
router.post('/delete', expressJoi(delete_article_schema), article_handler.deleteArticle)
// get  请求  遍历所有博客
router.get('/all', article_handler.allArticle)
// get  请求  根据id查看特定一篇博客
router.get('/show', expressJoi(show_article_schema), article_handler.showArticle)
// post 请求  根据用户搜索的关键字查找文章
router.post('/keySearch',expressJoi(keySearch_article_schema), article_handler.searchArticle)
// post 请求  根据分类查找文章 get请求
router.post('/sortSearch', expressJoi(searchSort_article_schema), article_handler.sortArticle)
// post请求   保存草稿
router.post('/save', expressJoi(save_article_schema), article_handler.savedraft)
// get 请求   把草稿拿出来展示在页面上
router.get('/get', article_handler.getDraft)
// post请求   删除所有草稿
router.post('/deleteDraft', article_handler.deletealldraft)
module.exports = router

